package com.dstz.demo.core.manager.impl;

import com.dstz.base.manager.impl.BaseManager;
import com.dstz.demo.core.dao.MatecodeDao;
import com.dstz.demo.core.manager.MatecodeManager;
import com.dstz.demo.core.model.Matecode;
import com.dstz.demo.utils.BaseTreeObj;
import com.dstz.demo.utils.TreeUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.*;

/**
 * 物料编码 Manager处理实现类
 * @author aschs
 * @email aschs@qq.com
 * @time 2019-12-28 17:42:44
 */
@Service("matecodeManager")
public class MatecodeManagerImpl extends BaseManager<String, Matecode> implements MatecodeManager {
	@Resource
	MatecodeDao matecodeDao;

	@Override
	public List<Matecode> queryByCode(Map map) {
		return this.matecodeDao.queryByCode(map);
	}

	@Override
	public Integer save(Matecode matecode) {
		return matecodeDao.save(matecode);
	}

	@Override
	public List<Matecode> lists(String ckey) {
		return matecodeDao.lists(ckey);
	}

	//查询所有的节点
	@Override
	public List<BaseTreeObj> findAll() {

		List<Matecode> all = matecodeDao.findAll();
		List<BaseTreeObj> list = new ArrayList<>();
		for(Matecode matecode : all){
			BaseTreeObj baseTreeObj = new BaseTreeObj();
			baseTreeObj.setId(matecode.getCkey());
			baseTreeObj.setName(matecode.getCname());
			baseTreeObj.setParentId(matecode.getPkey());
			list.add(baseTreeObj);
		}
		List<BaseTreeObj> list1 = TreeUtil.list2TreeConverter(list, "0");
		return list1;
	}

	@Override
	public List<Matecode> findthree() {
		return matecodeDao.findthree();
	}

	@Override
	public Matecode findMatecode(String ckey) {
		return matecodeDao.findMatecode(ckey);
	}


}
